program Delete4;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^ element;
  element = record
    value: integer;
    next: pelement;
  end;

procedure AddToBeginning (var head: pelement; num: integer);
var
  tmp: pelement;

begin
  tmp:= head;
  new (head);
  head^.next:=tmp;
  head^.value:=num;
end;

procedure PrintList (head: pelement);
var
  current: pelement;
begin
  current:=head;
  while (current <> nil) do
  begin
    writeln(current^.value);
    current:=current^.next;
  end;
end;

procedure AddToEnd (var head: pelement; num: integer);
var
  current: pelement;
begin
  if (head <> nil) then
  begin
    current:=head;
    while (current^.next <> nil) do
    begin
      current:=current^.next;
    end;
    new (current^.next);
    current^.next^.value:=num;
    current^.next^.next:=nil;
  end else begin
    AddToBeginning (head, num);
  end;
end;

function DeleteNumber4 (var head: pelement): integer;
var
  tmp, current: pelement;
  i: integer;
  c: boolean;
begin
  c:=true;
  current:=head;
  for i:=1 to 3 do
  begin
    if current^.next <> nil then
    begin
      current:=current^.next;
    end else begin
      write ('There are not enough elements!');
      writeln;
      c:= false;
    end;
  end;
  if c = true then
  begin
    if current <> nil then
    begin
      DeleteNumber4:=current^.value;
      tmp:=current^.next;
    end;
    current:= head;
    for i:= 1 to 2 do
    begin
      current:=current^.next;
    end;
    dispose (current^.next);
    current^.next:=tmp;
  end;
end;

var
  head: pelement;
  fin: Textfile;
  n, a, i: integer;

begin
  AssignFile (fin, 'input1.txt');
  Reset (fin);
  head:=nil;
  Read (fin, n);
  for i:= 1 to n do
  begin
    Read (fin, a);
    AddToEnd (head, a);
  end;
  DeleteNumber4 (head);
  PrintList (head);
  CloseFile (fin);
  readln;
end.
